package com.gdth.bank.utils;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.Map;

/**
 * SharedPreferences 基础封装类
 * Created by xjc on 9/14/15.
 */
public class SharedPreferManager {

    public static String get(Context context, String fileName, String key, String defaultValue) {
        SharedPreferences state = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
        return state.getString(key, defaultValue);
    }

    public static Map<String, ?> getAll(Context context, String fileName) {
        SharedPreferences state = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
        return state.getAll();
    }

    public static boolean getBoolean(Context context, String fileName, String key, boolean defaultValue) {
        SharedPreferences state = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
        return state.getBoolean(key, defaultValue);
    }

    public static long getLong(Context context, String fileName, String key, long defaultValue) {
        SharedPreferences state = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
        return state.getLong(key, defaultValue);
    }

    public static int getInt(Context context, String fileName, String key, int defaultValue) {
        SharedPreferences state = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
        return state.getInt(key, defaultValue);
    }

    public static void put(Context context, String fileName, String key, String value) {
        SharedPreferences state = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = state.edit();
        editor.putString(key, value);
        editor.commit();
    }

    public static void putInt(Context context, String fileName, String key, int value) {
        SharedPreferences state = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = state.edit();
        editor.putInt(key, value);
        editor.commit();
    }

    public static void putLong(Context context, String fileName, String key, long value) {
        SharedPreferences state = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = state.edit();
        editor.putLong(key, value);
        editor.commit();
    }

    public static void putBoolean(Context context, String fileName, String key, boolean value) {
        SharedPreferences state = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = state.edit();
        editor.putBoolean(key, value);
        editor.commit();
    }

    public static void clear(Context context, String fileName) {
        SharedPreferences state = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = state.edit();
        editor.clear();
        editor.commit();
    }

    public static void clearFieldValue(Context context, String fileName, String key) {
        SharedPreferences state = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = state.edit();
        editor.remove(key);
        editor.commit();
    }

}
